package org.youchan.aco.p2p;

import java.util.HashMap;
import java.util.Map;

import org.youchan.util.MessageHandler;
import org.youchan.util.MessagingQueue;
import org.youchan.util.StringMessage;

public class NegotiationManager implements MessageHandler<StringMessage> {
	private static NegotiationManager self_;
	
	Map<String, Negotiation> negotiations;
	MessagingQueue<StringMessage> queue;
	
	private NegotiationManager() {
		negotiations = new HashMap<String, Negotiation>();
		queue = new MessagingQueue<StringMessage>(this);
		queue.start();
	}
	
	public static NegotiationManager getInstance() {
		if (self_ == null) {
			self_ = new NegotiationManager();
		}
		return self_;
	}
	
	public boolean isNegotiated(String memberId) {
		return negotiations.containsKey(memberId);
	}
	
	public void negotiate() {
		queue.sendMessage(new StringMessage("negotiate"));
	}

	public void handle(StringMessage message) {
		_negotiate();
	}
	
	private void _negotiate() {
		
	}

}
